<?php
/**
 * 规则
 * Created by PhpStorm.
 * User: ZengYou
 * Date: 2018/9/19 0019
 * Time: 10:45
 */
namespace app\common\validate;

class AdminRule extends BaseValidate {

    protected $regex = [];

    protected $rule = [
        'id'          => 'require|number|max:10',
        'pid'         => 'require|number|max:10',
        'url'         => 'require|max:100',
        'name'        => 'require|max:50',
        'icon'        => 'require|max:50',
        'remark'      => 'require|max:255',
        'menu'        => 'require|in:0,1',
        'weigh'       => 'require|number|max:10',
        'shows'       => 'require|in:0,1'
    ];

    protected $message = [
        'id.require'          => 'ID不能为空',
        'id.number'           => 'ID只能是正整数',
        'id.max'              => 'ID长度不能超出10位',
        'pid.require'         => '父级ID不能为空',
        'pid.number'          => '父级ID只能是正整数',
        'pid.max'             => '父级ID长度不能超出10位',
        'url.require'         => 'URL不能为空',
        'url.max'             => 'URL长度不能超出100位',
        'name.require'        => '名称不能为空',
        'name.max'            => '名称长度不能超出50位',
        'icon.require'        => '图标不能为空',
        'icon.max'            => '图标长度不能超出50位',
        'remark.require'      => '备注不能为空',
        'remark.max'          => '备注长度不能超出255位',
        'menu.require'        => '菜单不能为空',
        'menu.in'             => '菜单不在选项内',
        'weigh.require'       => '权重不能为空',
        'weigh.number'        => '权重只能是正整数',
        'weigh.max'           => '权重长度不能超出10位',
        'shows.require'       => '状态不能为空',
        'shows.in'            => '显示不在选项内'
    ];

    /**
     * 添加
     */
    protected function sceneAdd()
    {
        return $this->only([
            'pid', 'url', 'name', 'icon', 'remark', 'menu', 'weigh', 'shows'
        ])->remove([
            'url'      => 'require',
            'icon'     => 'require',
            'remark'   => 'require',
            'weigh'    => 'require'
        ]);
    }

    /**
     * 编辑保存
     */
    protected function sceneEditSave()
    {
        return $this->only([
            'id', 'pid', 'url', 'name', 'icon', 'remark', 'menu', 'weigh', 'shows'
        ])->remove([
            'url'      => 'require',
            'icon'     => 'require',
            'remark'   => 'require',
            'weigh'    => 'require'
        ]);
    }

    /**
     * ID
     */
    protected function sceneId()
    {
        return $this->only(['id'])->remove([]);
    }

    /**
     * 编辑
     */
    protected function sceneEdit()
    {
        return $this->remove([
            'url'         => 'require',
            'remark'      => 'require',
            'weigh'       => 'require',
            'icon'        => 'require',
            'menu'        => 'require',
            'status'      => 'require'
        ]);
    }

}